<?php
/**
 * @author : lihui
 * @email  : lihui@mama.com
 * @time   : 2022/11/8 11:29
 */

namespace Xxb\XxbPhpAlgo;

class RBTreeNode
{
    // 结点颜色：1-黑色 2-红色
    const COLOR_BLACK = 1;
    const COLOR_RED = 2;

    private $color;

    /**
     * 左孩子结点
     * @var self
     */
    private $left;

    /**
     * 右孩子结点
     * @var
     */
    private $right;

    /**
     * 结点值
     * @var int
     */
    private $value;

    /**
     * @return int
     */
    public function getValue()
    {
        return $this->value;
    }

    /**
     * @param int $value
     */
    public function setValue($value)
    {
        $this->value = $value;
    }

    /**
     * @return self|null
     */
    public function getLeft()
    {
        return $this->left;
    }

    /**
     * @param self|null $left
     */
    public function setLeft($left)
    {
        $this->left = $left;
    }

    /**
     * @return self|null
     */
    public function getRight()
    {
        return $this->right;
    }

    /**
     * @param self|null $right
     */
    public function setRight($right)
    {
        $this->right = $right;
    }

    /**
     * @return mixed
     */
    public function getColor()
    {
        return $this->color;
    }

    /**
     * @param mixed $color
     */
    public function setColor($color)
    {
        $this->color = $color;
    }

    /**
     * RBTreeNode constructor.
     *
     * @param $value
     */
    public function __construct($value)
    {
        $this->setValue($value);
        // 因为不能往空结点加入新结点 所以新结点用红色表示
        $this->setColor(self::COLOR_RED);
    }
}
